//mongoimport --db infiniteScroll --collection news --file scrollData.json --jsonArray
var mongoose = require('mongoose');

//连接数据库
var DBURL = "mongodb://localhost:27017/infiniteScroll"
mongoose.connect(DBURL, {useNewUrlParser:true});
mongoose.connection.once("open", ()=>{
	console.log("mongoose connection open to " + DBURL);
})
mongoose.connection.on("error", ()=>{
	console.log("mongoose error!");
})

//添加schema--数据模型骨架
var Schema = mongoose.Schema;
var studentSchema = new Schema({
	name:{type:String},
	sex:{type:String},
	age:{type:Number},
	phone:{type:String},
	email:{type:String}
})

//添加model--操作数据库
//第一个参数是集合名
var student = mongoose.model('student', studentSchema);

var newsSchema = new Schema({
	userId:{type:Number},
	id:{type:Number},
	title:{type:String},
	body:{type:String}
})

var news = mongoose.model("news", newsSchema);

module.exports = {
	student:student,
	news:news
}